package com.jzsm.modules.sender.controller;

import com.jzsm.common.controller.BaseController;
import com.jzsm.common.core.domain.AjaxResult;
import com.jzsm.common.core.page.TableDataInfo;
import com.jzsm.common.utils.AssertUtils;
import com.jzsm.modules.sender.pojo.PushLog;
import com.jzsm.modules.sender.service.IPushLogService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("log")
@AllArgsConstructor
public class PushLogController extends BaseController {
    final IPushLogService pushLogService;

    /**
     * 查询列表
     *
     * @param log
     * @return
     */
    @GetMapping("list")
    public AjaxResult<TableDataInfo<PushLog>> getList(PushLog log) {
        startPage();
        List<PushLog> pushLogs = pushLogService.selectList(log);
        return AjaxResult.success(getDataTable(pushLogs));
    }

    /**
     * 根据业务id 查询
     *
     * @param businessId
     * @return
     */
    @GetMapping("business/{id}")
    public AjaxResult<TableDataInfo<PushLog>> getList(@PathVariable("id") String businessId) {
        PushLog log = new PushLog();
        log.setBusinessId(businessId);
        AssertUtils.isNotBlank("business id 不允许为空！", businessId);
        return AjaxResult.success(getDataTable(pushLogService.selectList(log)));
    }

    /**
     * 重发信息
     *
     * @param id
     * @return
     */
    @PostMapping("resendMessage/{id}")
    public AjaxResult<String> resendMessage(@PathVariable("id") String id) {
        return AjaxResult.success(pushLogService.resendMessage(id));
    }
}
